	<?php 
		include('inc/functions_blog.php');
		include 'inc/functions_like.php';
		
		$show_what = (isset($_GET['show'])) ? $_GET['show']:'all';
		switch ($show_what){
			case 'all':
			case 'group':
			case 'undefined':
			default:
				$latestWorkouts = listLatestWorkouts(getSettings('settings_trainings_to_show'));break;
			case 'friends':
				$latestWorkouts = listFriendsWorkouts(getSettings('settings_trainings_to_show'));break;
			case 'myfollowing':		
				$latestWorkouts = listFollowingWorkouts(getSettings('settings_trainings_to_show'));break;
		}
		 
	?>
	<?php 
	//	$latestWorkouts = array_reverse($latestWorkouts);
		foreach ($latestWorkouts as $key => $val )
		{ 
			$USER_PROFILE = new User('id', $val['user_id']);
			echo "<tr height=\"10\"><td colspan='2'><hr style='display: block;
			position: relative;
			padding: 0;
			margin: 8px auto;
			width: 100%;
			clear: both;
			border: none;
			border-top: 1px solid #AAA;
			border-bottom: 1px solid #FFF;
			font-size: 1px;
			line-height: 0;
			overflow: visible;' /></td></tr>";
			?>
            
			<tr>
            <td width="8%" rowspan="3" align="left" style="padding-right:10px;" valign="top" >
            
            
         <?php
		 // Get profile picture :)
		if($USER_PROFILE->getAvatarpath() != "")
		{
			$profile_pic_path = $CONFIG['user_data_path'] . $USER_PROFILE->getId() . "/thumbs_" . $USER_PROFILE->getAvatarpath();
			if(file_exists($profile_pic_path))
			{
				echo "<a href='index.php?action=profile&amp;id=" . $val['user_id'] . "'><img style='background: url(" . $profile_pic_path . ") no-repeat 50%; height: 60px; width: 60px;' src=\"" . $profile_pic_path . "\" alt=\"" . translate('profile_picture') . "\" /></a>\n";
			}
			else
			{
				echo "";//$profile_pic_path;
			}
		}
		else
		{
			if($USER_PROFILE->getGender() == "female")
			{
				echo "<center><a href='index.php?action=profile&amp;id=" . $val['user_id'] . "'><img src=\"" . $CONFIG['user_data_path'] . "profile_female.gif\" height='60' width='60' alt=\"" . translate('profile_picture') . "\" /></a></center>\n";
			}
			else
			{
				echo "<center><a href='index.php?action=profile&amp;id=" . $val['user_id'] . "'><img src=\"" . $CONFIG['user_data_path'] . "profile_male.gif\" height='60' width='60' alt=\"" . translate('profile_picture') . "\" /></a></center>\n";
			}
		}
		// Get profile picture END
		?>
           
          	</td>
            
			<td width="92%">
            <a style='color:#555555;' href="index.php?action=profile&amp;sub=show&amp;tid=<?php echo $val['training_id']; ?>"> <b> <?php echo htmlentities($val['title']); ?></b></a>
             
             <?php 
			 // Display time used on training
			 if($val['timespent_minutes'] != 0 || $val['timespent_hours'] != 0)
			 {
			?>
                <?php 
					//Display time user on training
				
					// Hours only
					if($val['timespent_hours'] > 0 && $val['timespent_minutes'] == 0)
					{
						echo "(" . $val['timespent_hours'] . translate('hours_short') . ")"; 
					}
					
                	// Hours and minutes, hours 
					elseif($val['timespent_hours'] > 0)
					{
						echo "(" . $val['timespent_hours'] . translate('hours_short');
					}
					// The And
					if($val['timespent_minutes'] > 0 && $val['timespent_hours'] > 0)
					{
						echo " " . strtolower(translate('and')) . " ";
					}
                 	
					// Minutes only
					if($val['timespent_minutes'] > 0 && $val['timespent_hours'] == 0)
					{
						echo "(" . $val['timespent_minutes'] . translate('minutes_short'). ")";
					}
					// Hours and minutes, minutes
					elseif($val['timespent_minutes'] > 0)
					{
						echo $val['timespent_minutes'] . translate('minutes_short') . ")";
					}
                ?>
            <?php
			 }
			 ?>
            </td>
            </tr>
            
            <tr>
            	<td>
            <?php 
			// Catch comments from training
			echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', strip_tags(substr(($val['comment']), 0, 130)) . "..." ); 
			?>
            	</td>
            </tr>
            
            <tr>
               <td>
               <font size="1">
                <div style='float: left; clear: right; padding-right: 2px;'><img src="img/flags/16/<?php echo strtolower($USER_PROFILE->getCountry()); ?>.png" alt="<?php echo $USER_PROFILE->getCountry(); ?>" /></div> 
                <a style='color:#555555;' href="index.php?action=profile&amp;id=<?php echo $val['user_id']; ?>"> <?php echo htmlentities($USER_PROFILE->getFirstname()) . " " . ucf(htmlentities($USER_PROFILE->getLastname())); ?></a>  <?php echo translate('for'); ?> <?php echo getHowLongAgo($val['date']); ?>. 
                <?php if(getCommentTraining($val['training_id']) >= 0):?>
				   <a class="detect_click" rel="<?php echo $val['training_id'];?>" onclick="javascript:open_comments(<?php echo $val['training_id'];?>,<?php echo $val['user_id'];?>);" style="text-decoration:none; color:#555555;" href="javascript:void(0);"><img src="./img/comments.png" alt="<?php echo translate('comments'); ?>" /> <?php echo (getCommentTraining($val['training_id'])>0)? getCommentTraining($val['training_id']): ""; ?></a>
                <?php else:?> 
					
				<?php endif;?>
				
                <?php if(getVideosTraining($val['training_id']) >= 1)
				{
				?>
                <img src="./img/video.png" alt="<?php echo translate('videos'); ?>" /> <?php echo getVideosTraining($val['training_id']); ?>
                <?php
				}
				?>
				<a href="javascript:void(0);" onclick="open_who_likes(<?php echo $val['training_id'];?>);"><img src="./img/thumb_up.png" alt="<?php echo translate('like');?>" /></a><span class="like" rel="<?php echo $val['training_id'];?>"> <?php echo (count_numberOfPersons_like($val['user_id'], $val['training_id']) >0)?count_numberOfPersons_like($val['user_id'], $val['training_id']):"";?>
                <?php if(is_like($val['user_id'],$_SESSION['user_id'], $val['training_id'])):?>
                	<a href="javascript:void(0);" onclick="like_unlike('unlike',<?php echo $_SESSION['user_id'];?>,<?php echo $val['user_id'];?>,<?php echo $val['training_id'];?>);" ><?php echo translate('unlike');?></a>
                <?php else:?>
                	<a href="javascript:void(0);" onclick="like_unlike('like',<?php echo $_SESSION['user_id'];?>,<?php echo $val['user_id'];?>,<?php echo $val['training_id'];?>);" ><?php echo translate('like');?></a>
                <?php endif;?>
                </span>
				<?php echo "&nbsp;".ui_aj_follow_this_user($val['user_id'], $val['user_id']);?>
                </font>
                <div class="clear comment_div" id="<?php echo $val['training_id'];?>">
					<?php echo UI_get_3_latest_comments($val['user_id'], $val['training_id']);?>
				</div>
               </td>
            </tr>
           
      <?php  } ?>
    	
     